module com {

	export class Node extends egret.Sprite {
		protected _baseAngle: number = 0;
		protected _baseRadius: number = 0;
		protected nodeChildList: Array<NodeChild> = null;

		public constructor(baseRadius: number, baseAngle: number) {
			super();
			this._baseRadius = baseRadius;
			this._baseAngle = ((baseAngle * Math.PI) / 180);
			this.nodeChildList = new Array();
			this.touchEnabled = false;
			this.touchChildren = false;
			this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
		}

		protected setNodeChildrenRadius(radius: number) {
			var child: NodeChild;
			var i: number = 0;
			while (i < this.nodeChildList.length) {
				child = this.nodeChildList[i];
				child.node.setBaseRadius((radius + child.baseRadiusOffset));
				i++;
			}
		}

		protected onEnterFrame(event: egret.Event) {
		}

		public destruct() {

			var child: NodeChild;
			this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
			this.graphics.clear();
			while (this.nodeChildList.length > 0) {
				child = this.nodeChildList.pop();
				this.removeChild(child.node);
				child.node.destruct();
				child = null;
			}
		}

		public setBaseRadius(radius: number) {
			this._baseRadius = radius;
		}

		public addChildNode(node: Node, baseRadiusOffset: number = 0) {
			this.nodeChildList.push(new NodeChild(node, baseRadiusOffset));
			this.addChild(node);
		}

	}

	class NodeChild extends egret.HashObject {
		public node: Node;
		public baseRadiusOffset: number = 0;
		public constructor(node: Node, baseRadiusOffset: number) {
			super();
			this.node = node;
			this.baseRadiusOffset = baseRadiusOffset;
		}

	}

}
